<?php

namespace app\admin\controller;

use app\common\model\Articlemodel;
use app\common\model\Category;
use app\common\model\Tag;

class Article extends Common {

    public function index() {
        $art_model = new \app\common\model\Article();



        return view('index', ['list' => null]);
    }

    // 添加文章
    public function add() {
        $art_model = new \app\common\model\Article();
        if (request()->isPost()){
            $input = input('post.');
            $ret = $art_model->store($input);
            if ($ret['valid']) {
                $this->success($ret['msg'], 'index','',1);
                exit;
            } else {
                $this->error($ret['msg'], null, '', 1);
                exit;
            }
        }

        // 获取分类数据
        $cateData = (new Category())->getTreeAll();
        $this->assign('cateData', $cateData);

        // 获取标签数据
        $tagData = Tag::all();
        $this->assign('tagData', $tagData);
        return $this->fetch();
    }

}
